import { Util } from '../../utils/util.js';
import { MerchantPackage } from './merchantPackage.js';

export class MerchantActivePackage {
    constructor({ packageInfo = null, isExpired = false, remainDays = null } = {}) {
        this.package = packageInfo ?? MerchantPackage.empty();
        this.isExpired = isExpired;
        this.remainDays = remainDays;
    }

    static fromJson(json) {
        const packageInfo = json.activePkg
            ? MerchantPackage.fromJson(json.activePkg)
            : MerchantPackage.empty();

        const isExpired = Util.jsonToBool(json.isActivePkgExpired, false);
        const remainDays = json.remainDays == null
            ? null
            : Util.jsonToInt(json.remainDays);

        return new MerchantActivePackage({ packageInfo, isExpired, remainDays });
    }
}
